
# 想在字节字符串上执行普通的文本操作
def demo_1():
    data = b'hello kepler'
    print(data[0:5])
    print(data.startswith(b'hello'))
    print(data.split())
    print(data.replace(b'hello', b'hello kepler'))

# 操作适用于字节数组
def demo_2():
    data = bytearray(b'hello kepler')
    print(data[0:5])
    print(data.startswith(b'hello'))
    print(data.split())
    print(data.replace(b'hello', b'hello kepler'))

# 不推荐使用字节字符串处理文本
def demo_3():
    s = b'Hello Kepler'
    print(s)
    print(s.decode('ascii'))
    print('{:10s} {:10d} {:10.2f}'.format('ACME', 100, 123.4).encode('ascii'))

if __name__ == '__main__':
    # demo_1()
    # demo_2()
    demo_3()